
package org.amos.upms.modules.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.amos.core.basic.annotation.Log;
import org.amos.core.basic.base.BaseController;
import org.amos.core.basic.constant.SystemConstant;
import org.amos.core.basic.utils.AmosUtils;
import org.amos.core.basic.vo.R;
import org.amos.upms.modules.system.dto.PostDTO;
import org.amos.upms.modules.system.entity.Post;
import org.amos.upms.modules.system.service.IPostService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 岗位表 前端控制器
 * </p>
 *
 * @author CodeGenerator
 * @since 2021-01-04
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/post")
public class PostController extends BaseController {

    private final IPostService postService;

    @GetMapping("/list")
    @Operation(description = "岗位列表信息")
    @Log(value = "岗位列表信息", logResultInfo = false)
    @SaCheckPermission("post:list")
    public R list(PostDTO dto) {
        List<Post> list = postService.list(buildWrapper(dto));
        return R.ok(list);
    }

    @PostMapping("/update")
    @Operation(description = "更新岗位数据")
    @Log(value = "更新岗位数据", logResultInfo = false)
    @SaCheckPermission("post:update")
    public R update(@RequestBody @Validated PostDTO dto) {
        Post dept = AmosUtils.copy(dto, Post.class);
        postService.saveOrUpdate(dept);
        return R.ok();
    }

    @PostMapping("/remove")
    @Operation(description = "删除岗位数据")
    @Log(value = "删除岗位数据", logResultInfo = false)
    @SaCheckPermission("post:update")
    public R remove(@RequestBody Set<Long> ids) {
        UpdateWrapper<Post> uw = new UpdateWrapper<>();
        uw.in(AmosUtils.toDbField(Post::getId), ids).set(AmosUtils.toDbField(Post::getIsDeleted), SystemConstant.SYS_DELETE_FLAG_ALREADY);
        postService.update(uw);
        return R.ok();
    }
}
